package medium;

import java.util.Arrays;
/*
179. 最大数
 */
public class LeeCode179 {

  public static void main(String[] args) {
    System.out.println(new LeeCode179().largestNumber(new int[]{3, 30, 34, 5, 9}));
  }

  public String largestNumber(int[] nums){
    String[] newNum = new String[nums.length];
    for (int i = 0; i < nums.length; i++) {
      newNum[i] = String.valueOf(nums[i]);
    }

    Arrays.sort(newNum,(a,b)->{
      return (b + a).compareTo(a + b);
    });

    if (newNum[0].equals("0")){
      return "0";
    }
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < newNum.length; i++) {
      stringBuilder.append(newNum[i]);
    }
    return stringBuilder.toString();
  }
}
